const applyForModel = require("../model/applyForModel");

//查询所有门店
module.exports.find = async function (searchObj,page) {
    // 分页查询
    let { current, size } = page;
    // 数据总条数
    let total = await applyForModel.countDocuments(searchObj);
    // 获取总页数: 数据总数 / 每页显示条数（注意要向上取整）
    let totalPage = Math.ceil(total / size);
    let rows = await applyForModel.find(searchObj)
    .populate({path:"admin"})
    .populate({path:"shopDoor"})
    .limit(parseInt(size)).skip((current - 1) * size);
    return {
        current, size, total, totalPage, rows
    }
}


//增加门店
module.exports.insert = async function (applyFor) {
    return await applyForModel.create(applyFor)
};
//删除门店
module.exports.delete = async function (id) {
    return await applyForModel.deleteOne([{ _id: id }])
}

//修改门店
module.exports.update = async function (id, applyFor) {
    return await applyForModel.updateOne({ _id: id }, applyFor)
}